/**
 * @description 静态资源上传到 阿里云 OSS
 */

const path = require('path')
const fse = require('fs-extra')
const { uploadFile } = require('../src/vendor/uploadOSS')

const publicPath = path.resolve(__dirname, '..', 'src', 'public')
const uploadPath = 'h5-assets'

async function main() {
  // 获取 src/public 下的所有文件
  const publicFiles = fse.readdirSync(publicPath)
  const files = publicFiles.filter(f => f !== 'favicon.ico') // 不上传 favicon.ico

  // 挨个上传
  const res = await Promise.all(
    files.map(fileName => {
      const filePath = path.join(publicPath, fileName)
      const name = `${uploadPath}/${fileName}` // oss 路径: bucket/h5-assets/xx.js
      return uploadFile(name, filePath)
    })
  )
  console.log('assets upload oss 上传成功', res)
}

main()
